package com.dfbz.demo01_实现TCP;

import java.net.DatagramPacket;
import java.net.InetAddress;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
public class Demo02_DatagramPacket{
    public static void main(String[] args) throws Exception {


        // UDP报文
        DatagramPacket packet = new DatagramPacket(
                "abc".getBytes(),
                "abc".getBytes().length,
                InetAddress.getByName("localhost"),
                8989
        );

        DatagramPacket packet2 = new DatagramPacket(
                "abc".getBytes(),
                "abc".getBytes().length
        );


        byte[] data = packet.getData();
        int length = packet.getLength();
        InetAddress address = packet.getAddress();
        int port = packet.getPort();

        System.out.println("getData(): " + new String(data));             // abc
        System.out.println("getLength(): " + length);                     // 3
        System.out.println("getAddress(): " + address.getHostAddress());  // 127.0.0.1
        System.out.println("getPort(): " + port);                         // 8989


    }
}
